package com.djinfo.work.dao.impl;

import com.djinfo.work.common.dao.impl.BaseDaoImpl;
import com.djinfo.work.dao.NewsDao;
import com.djinfo.work.entity.SysNewsEntity;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by gz on 2017/5/10.
 */
@Repository("newsDao")
public class NewsDaoImpl extends BaseDaoImpl implements NewsDao {
    @Override
    public void saveNews(SysNewsEntity news) {
        if(null==news.getId()){
            super.save(news);
        }else{
            super.update(news);
        }

    }

    @Override
    public List<SysNewsEntity> page(String hql, Integer pageNum, Integer pageSize) {

        return (List<SysNewsEntity>)super.pageQuery( hql,  pageNum,  pageSize);
    }

    @Override
    public List<SysNewsEntity> list(SysNewsEntity object) {
        String hql = " from SysNewsEntity where 1=1 ";
        return (List<SysNewsEntity>)super.getList(hql);
    }

    @Override
    public Integer getAllRowCount(String hql) {
        return super.getUniqueObject(hql).hashCode();
    }

    @Override
    public void update(SysNewsEntity object) {
        super.update(object);
    }

    @Override
    public void delete(SysNewsEntity object) {
        super.delete(this.selectOne(object));
    }

    @Override
    public SysNewsEntity selectOne(SysNewsEntity object) {
        return (SysNewsEntity)super.get(SysNewsEntity.class,object.getId());
    }

    @Override
    public SysNewsEntity getNewsById(String menuId) {
        return (SysNewsEntity)super.getByPrimaryKey(SysNewsEntity.class, menuId);
    }
}
